package com.vlong.town.service.honour;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vlong.town.entity.honour.HonourInfo;
import com.vlong.town.mapper.honour.HonourInfoMapper;

/**
 * 荣誉成就信息业务实现类
 * @author Assassin
 */
@Service
public class HonourInfoService {

    // Fields

    @Autowired
    private HonourInfoMapper honourInfoMapper;// 荣誉成就信息Mapper接口

    // Methods

    /**
     * 添加荣誉成就信息
     * @param townId 村镇Id
     * @param title 荣誉成就标题
     * @param content 荣誉成就内容
     * @param desc 荣誉成就简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void add(Long townId, String title, String content, String desc, String thumbnail) {
        HonourInfo honourInfo = new HonourInfo();
        honourInfo.setTownId(townId);
        honourInfo.setState(1);
        honourInfo.setStatus(1);
        honourInfo.setTitle(title);
        honourInfo.setContent(content);
        honourInfo.setDesc(desc);
        honourInfo.setThumbnail(thumbnail);
        Long cuTime = System.currentTimeMillis();
        honourInfo.setCreateTime(cuTime);
        honourInfo.setUpdateTime(cuTime);
        this.honourInfoMapper.insert(honourInfo);
    }

    /**
     * 逻辑删除荣誉成就信息
     * @param honourId 主键值
     */
    @Transactional
    public void delete(Long honourId) {
        this.honourInfoMapper.delete(honourId);
    }

    /**
     * 修改荣誉成就信息
     * @param honourId 荣誉成就Id
     * @param title 荣誉成就标题
     * @param content 荣誉成就内容
     * @param desc 荣誉成就简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void update(Long honourId, String title, String content, String desc, String thumbnail) {
        HonourInfo honourInfo = new HonourInfo();
        honourInfo.setHonourId(honourId);
        honourInfo.setTitle(title);
        honourInfo.setContent(content);
        honourInfo.setDesc(desc);
        honourInfo.setThumbnail(thumbnail);
        honourInfo.setUpdateTime(System.currentTimeMillis());
        this.honourInfoMapper.update(honourInfo);
    }

    /**
     * 主键查询荣誉成就信息
     * @param honourId 荣誉成就Id
     * @return
     */
    @Transactional(readOnly = true)
    public HonourInfo queryById(Long honourId) {
        return this.honourInfoMapper.selectById(honourId);
    }

    /**
     * 查询荣誉成就信息
     * @param title 荣誉成就标题
     * @param content 荣誉成就内容
     * @param desc 荣誉成就简介
     * @return List<HonourInfo>
     */
    @Transactional(readOnly = true)
    public List<HonourInfo> queryList(String title, String content, String desc) {
        HonourInfo honourInfo = new HonourInfo();
        honourInfo.setTitle(title);
        honourInfo.setContent(content);
        honourInfo.setDesc(desc);
        return this.honourInfoMapper.selectList(honourInfo);
    }

}
